package object.obj3D;

import javax.microedition.khronos.opengles.GL10;

import object.GameObject;
import object.TransMatrix;
import object.obj3D.enemy.Cube;
import system.Device;
import system.Graphics;
import MD2Model.MD2Model;

public class Object3D extends GameObject {
	protected MD2Model model;
	
	private TransMatrix mat = new TransMatrix();
	private GL10 gl;
	
	protected int FrameIndex = 0;
	protected int AnimIndex = 0;
	

	private Cube m_cube = new Cube();

	public Object3D(int modelID, int resTexID, boolean isLoop) {
		gl = Graphics.GetGraphics();
		model = new MD2Model(gl, Device.GetContext(), modelID, resTexID, isLoop);
	}
	
	public Object3D (MD2Model obj){
		gl = Graphics.GetGraphics();
		model = obj;
	}

	private boolean isDisplay = true;

	public void Render() {
		if (!isDisplay)
			return;

		gl.glMatrixMode(GL10.GL_MODELVIEW);
		gl.glPushMatrix();
		gl.glLoadIdentity();
		mat.TranslateRender(gl);

//		gl.glDisable(GL10.GL_TEXTURE_2D);
//		gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
//		m_cube.draw(gl);
//		gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

		gl.glEnable(GL10.GL_TEXTURE_2D);

		model.Render(gl, AnimIndex,FrameIndex);
		gl.glPopMatrix();
	}
	
	public void SetPlay(boolean isPlay)
	{
		isDisplay = isPlay;
	}

	public void Stop() {
		isDisplay = false;
	}

	public boolean IsPlaying() {
		return isDisplay;
	}

	public int GetNumAnim() {
		return model.GetNumAnim();
	}

	public void SetAnimation(int index) {
		model.SetAnimation(index);
	}

	public void SetBound(float[] cube) {
		mat.SetBound(cube);
	}

	public void SetRotateX(float angle) {
		mat.SetRotateX(angle);
	}
	public void SetRotateY(float angle) {
		mat.SetRotateY(angle);
	}
	public void SetRotateZ(float angle) {
		mat.SetRotateZ(angle);
	}
	
	public void SetRotateOX(float angle){
		mat.SetRotateOX(angle);
	}
	
	public void SetRotateOY(float angle){
		mat.SetRotateOY(angle);
	}
	
	public void SetRotateOZ(float angle){
		mat.SetRotateOZ(angle);
	}

	public void SetTranslateZ(float distanceZ) {
		mat.SetTranslateZ(distanceZ);
	}
	
	public void SetTranslateX(float distanceX) {
		mat.setTranslateX(distanceX);
	}

	public void SetTranslateY(float transY) {
		mat.setTranslateY(transY);
	}

	public void SetScale(float x, float y, float z) {
		mat.SetScale(x, y, z);
	}

	public float GetTranslateZ() {
		return mat.getTranslateZ();
	}
	
	public float GetTranslateX() {
		return mat.getTranslateX();
	}
	
	public float GetTranslateY() {
		return mat.getTranslateY();
	}
	
	
	public float GetRotateOX(){
		return mat.getRotateOX();
	}
	
	public float GetRotateOY(){
		return mat.getRotateOY();
	}
	
	public float GetRotateOZ(){
		return mat.getRotateOZ();
	}
	
	public float GetRotateX(){
		return mat.getRotateX();
	}
	
	public float GetRotateY(){
		return mat.getRotateY();
	}
	
	public float GetRotateZ(){
		return mat.getRotateZ();
	}
	
	public float GetScaleX(){
		return mat.getScaleX();
	}
	
	public float GetScaleY(){
		return mat.getScaleY();
	}
	
	public float GetScaleZ(){
		return mat.getScaleZ();
	}

	public TransMatrix getMatrix() {
		return mat;
	}
	public float GetDistance(){
		return mat.GetDistance();
	}
}
